package calorie.com.calorie.contact;

import android.content.Context;



import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.request.LoginRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;

public class LoginContact {


    public static class LoginPresent extends BasePresent<ILoginView> {
        public void login(final Context context, String user, String pwd){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            LoginRequest request=new LoginRequest(user, pwd);
            service.login(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView()!=null){
                        getView().getLoginData(response);
                    }
                }

                @Override
                public void onFailed() {
                    if (getView()!=null){
                        getView().getDataFailed();
                    }

                }
            });

        }
    }


    public interface ILoginView extends IBaseView {
        void getLoginData(Response<ResultDTO> response);
        void getDataFailed();
    }
}
